package task

import (
	"time"

	. "gddgame.cc/galaxy/common/dsl/game"
	. "gddgame.cc/galaxy/common/dsl/game/reward"
)

const GameTaskName = "game_task"

type GameTask struct {
	Id         int               `json:"id" orm:"auto" sql:"INT"`
	Name       map[string]string `json:"name" sql:"JSON"`
	Desc       map[string]string `json:"desc" sql:"JSON"`
	Type       TaskType          `json:"type" sql:"TINYINT"`
	Difficult  int               `json:"difficult" sql:"INT"`
	IsAddUp    bool              `json:"is_add_up" msg:"TINYINT"`
	Factors    []Factor          `json:"factors" sql:"JSON"`
	TargetId   string            `json:"target_id" sql:"VARCHAR"`
	Reward     Reward            `json:"reward" sql:"JSON"`
	StartTime  *time.Time        `json:"start_time" sql:"DATETIME"`
	ExpireTime *time.Time        `json:"expire_time" sql:"DATETIME"`

	// 扩展参数：游戏端
	Extend interface{} `json:"extend" sql:"JSON"`
	// 扩展参数：服务端
	Inside interface{} `json:"inside" sql:"JSON"`

	goal int32
}

func (task *GameTask) GetGoal() int32 {
	if task.goal > 0 {
		return task.goal
	}
	task.goal = int32(0)
	for _, factor := range task.Factors {
		task.goal += factor.Value
	}
	return task.goal
}
